package Command;

import Server.Command;
import Server.cmdArguments;

public class InsertCommand implements Command {
	private cmdArguments args;
	private Integer i;

	public InsertCommand() {}

	@Override
	public String execute() {
		String result = "";
		try {
			i = Integer.parseInt(args.commands[1].trim());
			args.ds.add(i);
			if(args.db){
				result = "Inserted: " + i;
			} else {
				result = "Inserter " + i + " to the dataset, commit to make insert final.";
			}
		} catch (Exception e) {
			result = "Missing or incorrect argument";
		}
		return result;
	}

	@Override
	public String undo() {
		if (args.ds.remove(i))
			return "Undid adding: " + i + ".";
		return "Undo failed.";
	}

	@Override
	public void setArgs(cmdArguments args) {
		this.args=args;
	}
}